package com.sangu.dianxiu;

import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;
import android.widget.Toast;

import com.android.volley.VolleyError;
import com.baidu.mapapi.SDKInitializer;
import com.sangu.dianxiu.bean.basedata.CityEntity;
import com.sangu.dianxiu.bean.basedata.CountyEntity;
import com.sangu.dianxiu.bean.user.LoginEntity;
import com.sangu.dianxiu.bean.user.User;
import com.sangu.dianxiu.config.Constants;
import com.sangu.dianxiu.netstate.NetChangeObserver;
import com.sangu.dianxiu.netstate.NetWorkUtil;
import com.sangu.dianxiu.netstate.NetworkStateReceiver;
import com.sangu.dianxiu.utils.CheckUtils;
import com.sangu.dianxiu.utils.FrescoHelper;
import com.sangu.dianxiu.utils.ImageLoaderUtils;
import com.sangu.dianxiu.utils.UserManager;

import java.util.ArrayList;
import java.util.HashMap;


/**
 * 在app刚启动的时候就运行此类，用来进行一些全局配置，要在AndroidManifest文件中的Application标签中注册此类，否则app刚启动的时候不会运行此类
 * Created by Administrator on 15-11-2.
 */
public class BaseApp extends Application {
    private static BaseApp app;     //Application的实例类
    public static User user=null;   //用户实例
    public static boolean isLogin=false;    //用来判定用户是否登录
    public static ArrayList<CityEntity.CitiesEntity> citiesEntity;
    public static ArrayList<CountyEntity.CountiesEntity> countiesEntity;
    public static boolean isModifying=false;    //用来判定订单是否是修改状态
    public static BaseApp getInstance() {
        return app;
    }
    @Override
    public void onCreate() {
        super.onCreate();
        app=this;
        initNetState();
        ImageLoaderUtils.configGlobalImageLoader(this); //UniversalImageLoader图片加载全局配置
        SDKInitializer.initialize(this);        //使用百度地图的时候要调用这个进行初始化
        FrescoHelper.getImagePipelineConfig(this);  //Fresco图片加载全局配置

    }
    //注册网络监听
    private NetChangeObserver observer = new NetChangeObserver() {
        @Override
        public void onConnect(NetWorkUtil.NetType type) {
            super.onConnect(type);
            switch (type) {
                case WIFI:
                    showToast("亲!WIFI已连接");
                    break;
                case GNET_3:
                    showToast("移动3G网络已连接!!!");
                    break;
                default:
                    showToast("亲!网络已连接");
                    break;
            }
        }
        @Override
        public void onDisConnect() {
            super.onDisConnect();
            showToast("网络未连接,请打开网络!!!");
        }
    };
    //初始化网络监听
    private void initNetState() {
        NetworkStateReceiver.registerNetworkStateReceiver(this);
        NetworkStateReceiver.registerObserver(observer);
    }
    public void unegisterNetworkStateReceiver() {
        NetworkStateReceiver.removeRegisterObserver(observer);
        NetworkStateReceiver.unRegisterNetworkStateReceiver(this);
    }

    public void showToast(String msg)
    {
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
    }
}
